package Map;

import java.util.HashMap;
import java.util.Map;

/**
 * @Grup:Map
 * @Auther:cola
 * @Data:2021/3/27-2021-03-22:19
 * @version:1.0
 */
public class MapNewMethodDemo {
    public static void main(String[] args) {
        Map<Integer, String> map = new HashMap<>();
        map.put(1, "jack");
        map.put(2, "tom");
        map.put(3, "lily");
        String value = map.getOrDefault(1, "null");
        System.out.println(value);

        /*String s=map.get(5);
        if (s==null){
            System.out.println();
        }else {

        }*/
        String val = map.put(3, "ff");
        System.out.println(val);

        //只会添加不存在相同Key的值
        String va = map.putIfAbsent(3, "vince");
        System.out.println(va);
        map.forEach((k, v) -> System.out.println(k + "->" + v));

        map.replace(3, "vince");
        map.replace(3, "lily", "vince");

        map.compute(1, (k, v1) -> v1 + "1");
        map.computeIfAbsent(5, (val1) -> val1 + "test");

        map.merge(8, "888", (oldVal, newVal) -> oldVal + newVal);
        map.forEach((k, v) -> System.out.println(k + "->" + v));

    }
}
